package com.dd.keel.core.common.utils;

import java.util.LinkedList;
import java.util.Random;
import java.util.UUID;

/**
 * Random util
 * @author Kevin.XU
 *
 */
public class RandomUtil {
	
	private static Random global_random = new Random();
	private static CycleCounter global_cycle_counter = new CycleCounter(0,9999);
	
	public static long cycleLong()
	{
		return global_cycle_counter.next();
	}
	
	public static int randomInt(int max)
	{
		return global_random.nextInt(max);
	}
	
	public static long randomLong()
	{
		return global_random.nextLong();
	}
	
	public static String randomUUID()
	{
		UUID uuid = UUID.randomUUID(); 
		return uuid.toString();
	}
	
	/**
	 * min value is 0, it means [0,maxValue]
	 * place items by randomized order 
	 * @param maxValue
	 * @return
	 */
	public static int[] randomIntSequence(int maxValue)
	{
		LinkedList<Integer> targetList = new LinkedList<Integer>();
		int[] result = new int[maxValue+1];
		for(int i=0; i<=maxValue; ++i)
		{
			targetList.add(new Integer(i));
		}
		int randomIndex = 0;
		int randomValue = 0;
		for(int i=0; i<=maxValue; ++i)
		{
			randomIndex = randomInt(targetList.size());
			randomValue = targetList.remove(randomIndex).intValue();
			result[i] = randomValue;
		}
		return result;
	}
	
}
